package org.credo.socket.thread;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class MyClient {

	public static void main(String[] args) throws UnknownHostException, IOException {
		Socket socket = new Socket("127.0.0.1", 30000);
		new Thread(new clientThread(socket)).start();
		PrintStream ps=new PrintStream(socket.getOutputStream());
		String line=null;
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		System.out.println("br:"+br);
		while((line=br.readLine())!=null){
			ps.println(line);
		}
	}

}

class clientThread implements Runnable {
	private Socket socket;
	BufferedReader br = null;

	public clientThread(Socket s) throws IOException {
		this.socket = s;
		this.br = new BufferedReader(new InputStreamReader(s.getInputStream()));
	}

	@Override
	public void run() {
		String content = null;
		try {
			while ((content = br.readLine()) != null) {
				System.out.println(content);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}